package com.qike.baoxiu.controller;

import com.qike.baoxiu.config.PassToken;
import com.qike.baoxiu.dto.*;
import com.qike.baoxiu.response.BaseResult;
import com.qike.baoxiu.response.RetResponse;
import com.qike.baoxiu.service.OrderService;
import com.qike.baoxiu.service.UserService;
import com.qike.baoxiu.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: baoxiu
 * @author: Eric
 * @create: 2020-06-09 13:01
 */
@RestController
@CrossOrigin
@Api(description = "pad接口")
@RequestMapping("/pad")
public class PadController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private UserService userService;



    /**
     * 维修单列表
     * @return
     */
    @ApiOperation("维修单列表")
    @GetMapping("/orderList")
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true) })
    @ResponseBody
    public BaseResult orderList(OrderListDto orderListDto) {
        try {
            OrderListVo vo = orderService.orderList(orderListDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 维修单详情
     * @return
     */
    @ApiOperation("维修单详情")
    @GetMapping("/orderInfo")
    @ResponseBody
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true) })
    public BaseResult orderInfo(Integer id) {
        try {
            OrderInfoVo vo = orderService.orderInfo(id);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 接单
     * @return
     */
    @ApiOperation("接单")
    @GetMapping("/receiving")
    @ResponseBody
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true) })
    public BaseResult receiving(Integer id) {
        try {
             orderService.receiving(id);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     *
     * @return
     */
    @ApiOperation("完成订单")
    @PostMapping("/finishOrder")
    @ResponseBody
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true) })
    public BaseResult finishOrder(@RequestBody FinishOrderDto finishOrderDto ) {
        try {
            orderService.finishOrder(finishOrderDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 添加用户
     * @return
     */
    @ApiOperation("添加用户")
    @PostMapping("/addUser")
    @ResponseBody
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true) })
    public BaseResult addUser(@RequestBody AddUserDto addUserDto) {
        try {
            UserVo userVo = orderService.PadAddUser(addUserDto);
            return RetResponse.makeOKRsp(userVo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 登录
     *
     * @param loginDto
     * @return
     */
    @ApiOperation("登录")
    @PostMapping("/Login")
    @ResponseBody
    @PassToken
    public BaseResult Login(@RequestBody LoginDto loginDto) {
        try {
            LoginVo vo = userService.login(loginDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 修改密码
     *
     * @param
     * @return
     */
    @ApiOperation("修改密码")
    @PostMapping("/changPwd")
    @ResponseBody
    public BaseResult changPwd(@RequestBody ChangPwdDto changPwdDto) {
        try {
             userService.changPwd(changPwdDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 搜索知识库
     *
     * @param
     * @return
     */
    @ApiOperation("搜索知识库")
    @GetMapping("/searchKnowledge")
    @ResponseBody
    public BaseResult searchKnowledge(SearchKnowledgeDto searchKnowledgeDto) {
        try {
            KnowledgeListVo vo =  orderService.searchKnowledge(searchKnowledgeDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 搜索知识库
     *
     * @param
     * @return
     */
    @ApiOperation("解决方案查询")
    @GetMapping("/searchFix")
    @ResponseBody
    public BaseResult searchFix(SearchKnowledgeDto searchKnowledgeDto) {
        try {
            List<KnowledgeVo> list =  orderService.searchFix(searchKnowledgeDto);
            return RetResponse.makeOKRsp(list);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }


    /**
     * 消息列表
     *
     * @param
     * @return
     */
    @ApiOperation("消息列表")
    @GetMapping("/messageList")
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true) })
    @ResponseBody
    public BaseResult messageList(MessageListDto messageListDto) {
        try {
            MessageListVo vo =  orderService.messageList(messageListDto);
            return RetResponse.makeOKRsp(vo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 未读消息数量
     * @return
     */
    @ApiOperation("未读消息数量")
    @GetMapping("/unReadCount")
    @ResponseBody
    @ApiImplicitParams({ @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "token标记", required = true) })
    public BaseResult unReadCount() {
        try {
            Integer num = orderService.unReadCount();
            return RetResponse.makeOKRsp(num);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 读取消息
     *
     * @param
     * @return
     */
    @ApiOperation("读取消息")
    @GetMapping("/readMessage")
    @ResponseBody
    public BaseResult readMessage(Integer id) {
        try {
           orderService.readMessage(id);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 未处理订单接口
     *
     * @param
     * @return
     */
    @ApiOperation("未处理订单接口")
    @GetMapping("/unTakeOrderSize")
    @ResponseBody
    public BaseResult unTakeOrderSize() {
        try {
           Integer size =  orderService.unTakeOrderSize();
            return RetResponse.makeOKRsp(size);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 未处理订单接口
     *
     * @param
     * @return
     */
    @ApiOperation("判断月报是否需要上传")
    @GetMapping("/monthReportIsUpLoad")
    @ResponseBody
    public BaseResult monthReportIsUpLoad() {
        try {
            Boolean flag =  orderService.monthReportIsUpLoad();
            return RetResponse.makeOKRsp(flag);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }
    /**
     * 月报上传
     * @return
     */
    @ApiOperation("月报上传")
    @DeleteMapping("/monthReport")
    @ResponseBody
    public BaseResult monthReport(MonthReportDto monthReportDto) {
        try {
            orderService.monthReport(monthReportDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }



    /**
     * 企业微信创建订单
     *
     * @param
     * @return
     */
    @ApiOperation("企业微信创建订单")
    @PostMapping("/weChartAddOrder")
    @ResponseBody
    public BaseResult weChartAddOrder(@RequestBody WeChartAddOrderDto weChartAddOrderDto) {
        try {
            orderService.weChartAddOrder(weChartAddOrderDto);
            return RetResponse.makeOKRsp();
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }

    /**
     * 企业微信创建订单跳转
     *
     * @param
     * @return
     */
    @ApiOperation("企业微信创建订单跳转,获取用户信息")
    @GetMapping("/weChartUserInfo")
    @ResponseBody
    public BaseResult weChartUserInfo(String weChartUid) {
        try {
            UserInfoVo  userInfoVo = orderService.weChartUserInfo(weChartUid);
            return RetResponse.makeOKRsp(userInfoVo);
        } catch (Exception e) {
            return RetResponse.makeErrRsp(e.getMessage());
        }
    }
}